{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('a', 3), ('b', 2), ('e', 4), ('v', 2), ('f', 3), ('g', 3), ('d', 3)]\n",
      "[('c', 1), ('s', 1), ('h', 1), ('r', 1)]\n"
     ]
    }
   ],
   "source": [
    "nums = 'abcevaefegsgdghfdefavbdr'\n",
    "length = len(nums)\n",
    "states = [False] * length\n",
    "\n",
    "samenums = []\n",
    "diffnums = []\n",
    "for i in range(length):\n",
    "    #flag = False\n",
    "    count = 0\n",
    "    if states[i]:\n",
    "        continue\n",
    "    for j in range(i+1,length):\n",
    "        if states[j]:\n",
    "            continue\n",
    "        if nums[i] == nums[j]:\n",
    "            #flag = True\n",
    "            count += 1\n",
    "            states[j] = True\n",
    "    if count:\n",
    "        states[i] = True\n",
    "        samenums.append((nums[i],count + 1))\n",
    "    else:\n",
    "        diffnums.append((nums[i],count + 1))\n",
    "        \n",
    "print(samenums)\n",
    "print(diffnums)\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[('e', 4), ('a', 3), ('f', 3), ('g', 3), ('d', 3), ('b', 2), ('v', 2)]\n"
     ]
    }
   ],
   "source": [
    "nums = [('a', 3), ('b', 2), ('e', 4), ('v', 2), ('f', 3), ('g', 3), ('d', 3)]\n",
    "length = len(nums)\n",
    "\n",
    "\n",
    "for i in range(length):\n",
    "    flag = True\n",
    "    for j in range(length-1-i):\n",
    "       \n",
    "        if nums[j][1] < nums[j+1][1]:\n",
    "            temp = nums[j]\n",
    "            nums[j] = nums[j+1]\n",
    "            nums[j+1] = temp\n",
    "           \n",
    "            flag = False\n",
    "    if flag:\n",
    "        break\n",
    "print(nums)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
